import 'dart:typed_data';

import 'package:flutter_test/flutter_test.dart';
import 'package:sow_app/repository/model/ajax_response_model.dart';
import 'package:sow_app/repository/model/book_classify_model.dart';
import 'package:sow_app/repository/model/book_shelf_model.dart';
import 'package:sow_app/repository/model/captcha_image_model.dart';
import 'package:sow_app/repository/model/chapter_model.dart';
import 'package:sow_app/repository/model/novel_model.dart';
import 'package:sow_app/repository/model/paged_data_model.dart';
import 'package:sow_app/repository/model/register_request_model.dart';
import 'package:sow_app/repository/model/search_model.dart';
import 'package:sow_app/repository/model/token_model.dart';
import 'package:sow_app/repository/model/user_info_model.dart';

void main() {
  test(
    "should return all valid Model when invoke fromJson()",
    () async {
      // arrange
      AjaxResponseModel ajaxResponseModel = AjaxResponseModel.fromJson(
          {"code": "0", "msg": "msg", "data": "data"});
      CaptchaImageModel captchaImageModel =
          CaptchaImageModel.fromJson({"uuid": "uuid", "img": Uint8List(0)});
      UserInfoModel userInfoModel = UserInfoModel.fromJson(
        {'username': "0", 'nickName': "nickName"},
      );
      NovelModel novelModel = NovelModel.fromJson({
        "id": "2",
        "authorId": userInfoModel.userId.toString(),
        "userName": userInfoModel.userId.toString(),
        "authorName": userInfoModel.nickName,
        "bookName": "傀儡"
      });
      RegisterRequestModel registerRequestModel =
          RegisterRequestModel.fromJson({
        'userName': "userName",
        'password': "password",
        'nickName': "nickName",
      });
      TokenRequestModel tokenRequestModel = TokenRequestModel.fromJson({
        'username': "username",
        'password': "password",
        'code': "code",
        'uuid': "uuid",
      });
      PagedDataModel pagedDataModel = PagedDataModel(0, []);
      PagedDataModel nullPagedDataModel = PagedDataModel(null, null);
      SearchModel searchModel =
          SearchModel.fromJson({"searchContent": "searchContent"});
      ChapterModel chapterModel = ChapterModel.fromJson({
        'bookId': "0",
        'id': "0",
        'indexNum': "0",
        'indexName': "title",
        'content': "content"
      });
      BookClassifyModel bookClassifyModel = BookClassifyModel.fromJson(
          {"id": '1', "name": '2', 'parentId': '1', 'parentName': '2'});
      BookShelfModel bookShelfModel = BookShelfModel.fromJson({
        'bookId': 'bookId',
        'bookName': 'bookName',
        'catId': 'catId',
        'catName': 'catName',
        'wordCount': 'wordCount',
        'visitCount': 'visitCount',
        'isVip': 'isVip',
        'lastIndexUpdateTime': 'lastIndexUpdateTime',
        'user': userInfoModel,
      });
      // act
      final ajaxResponse = ajaxResponseModel.toJson();
      final captchaImage = captchaImageModel.toJson();
      final novel = novelModel.toJson();
      final registerRequest = registerRequestModel.toJson();
      final tokenRequest = tokenRequestModel.toJson();
      final userInfo = userInfoModel.toJson();
      final pagedData = pagedDataModel.toJson();
      final nullPagedData = pagedDataModel.toJson();
      final search = searchModel.toJson();
      final chapter = chapterModel.toJson();
      final bookClassify = bookClassifyModel.toJson();
      final bookShelf = bookShelfModel.toJson();

      // assert
      expect(ajaxResponse, isNotEmpty);
      expect(captchaImage, isNotEmpty);
      expect(novel, isNotEmpty);
      expect(registerRequest, isNotEmpty);
      expect(tokenRequest, isNotEmpty);
      expect(userInfo, isNotEmpty);
      expect(ajaxResponseModel, isNotNull);
      expect(captchaImageModel, isNotNull);
      expect(novelModel, isNotNull);
      expect(registerRequestModel, isNotNull);
      expect(tokenRequestModel, isNotNull);
      expect(userInfoModel, isNotNull);
      expect(pagedDataModel, isNotNull);
      expect(pagedData, isNotEmpty);
      expect(nullPagedDataModel, isNotNull);
      expect(nullPagedData, isNotEmpty);
      expect(searchModel, isNotNull);
      expect(search, isNotEmpty);
      expect(chapter, isNotEmpty);
      expect(bookClassify, isNotEmpty);
      expect(bookShelf, isNotEmpty);
    },
  );
}
